package tech.wetech.admin3.sys.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.wetech.admin3.sys.model.DID;
import tech.wetech.admin3.sys.repository.DIDRepository;

import java.util.List;

@Service
public class DIDService {
  private DIDRepository didRepository;

  public DIDService(DIDRepository didRepository) {
    this.didRepository = didRepository;
  }

  @Transactional
  public DID createDID(DID did) {
    return didRepository.save(did);
  }

  @Transactional
  public DID update(DID did) {
    return didRepository.save(did);
  }

  public DID findByDidNo(String didNo) {
    return didRepository.findByDidNo(didNo);
  }

  public DID findBySerial(String serial) {
    return didRepository.findBySerial(serial);
  }

  public DID findByModelFileHash(String modelFileHash) {
    return didRepository.findByModelFileHashes(modelFileHash);
  }

  public DID findByImageHash(String imageHash) {
    return didRepository.findByImageHashes(imageHash);
  }

  public List<DID> getAll() {
    return didRepository.findAll();
  }

  public Integer count() {
    return didRepository.countBy();
  }

  public DID findByName(String name) {
    return didRepository.findByName(name);
  }


  public Integer findMaxId() {
    return didRepository.findMaxId();
  }

  @Transactional
  public void deleteBySerial(String serial) { didRepository.deleteBySerial(serial);}
}
